<#include "./template/general_temp.ftl">

<#macro content>
<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-people"></i>属性管理</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>

            <div class="box-content">
                <div class="alert alert-info box col-md-12">
                    <div class="col-md-6">
                        <a class="btn btn-success" href="${base}/system/meta/add"><i class="glyphicon glyphicon-plus icon-white"></i>新增</a>
                    </div>
                    <div class="col-md-6">
                        <form class="form-inline" role="form">
                            <div class="form-group">
                                <select id="catSelect" class="form-control">
                                    <option value="0" selected="selected">全部</option>
                                    <option value="1">产品类型</option>
                                    <option value="2">平台类型</option>
                                    <option value="3">公司类型</option>
                                    <option value="4">大咖类型</option>
                                </select>
                            </div>
                            <button type="button" onclick="queryData()" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
                        </form>
                    </div>
                </div>
                <table id="meta_dg">
                </table>
            </div>
        </div>
    </div>
    <!--/span-->

</div><!--/row-->
</#macro>

<#macro script>
<script type="text/javascript">
    function getQueryCondition(){
        var cat = $("#catSelect").val();
        return {"type":cat};
    }
    function queryData(){
        var pars=getQueryCondition();
        //构造列表
        jQuery('#meta_dg').datagrid({
            url:'${base}/system/meta/list',
            fitColumns : true,
            striped : true,
            pagination : true,
            rownumbers : true,
            pageSize : 20,
            pageNumber : 1,
            pageList : [ 20, 50],
            loadMsg : '数据正在加载中...',
            singleSelect:true,
            queryParams : pars,
            selectOnCheck : false,
            checkOnSelect : false,
            width:$('.box-content').width() * 0.985,
            columns : [[
                {field : 'name', title : '名称',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'typeStr', title : '类别',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center'},
                {field : 'ctrl', title : '操作',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.05, align: 'center',
                    formatter:function(value,row,index){
                        var editBtn = "<a class='btn btn-info' href='javascript:void(0)' onclick='edit(" + row.id +")'><i class='glyphicon glyphicon-edit icon-white'></i>编辑</a>";
                        var delBtn = "<a class='btn btn-primary' href='javascript:void(0)' onclick='del(" + row.id +")'><i class='glyphicon glyphicon-trash icon-white'></i>删除</a>"
                        return editBtn + delBtn;
                    }
                }
            ]],
            onLoadSuccess:function(data){
            },
            onClickRow: function (rowIndex, rowData) {

            }
        });
    }

    $(document).ready(function () {
        queryData();
    });

    function edit(id){
        window.location = "${base}/system/meta/edit?id=" + id;
    }
    function del(id){
        if(window.confirm("确认删除？")) {
            jQuery.ajax({
                type: "POST",
                url: '${base}/system/meta/delete',
                dataType:"json",
                data: {"id": id},
                success: function(data){
                    if(data.status == 1) {
                        alert("删除成功！");
                        queryData();
                    }
                },
                error: function (obj){
                    console.info(obj);
                }
            });
        }
    }
</script>
</#macro>
